home *** CD-ROM | disk | FTP | other *** search
/ Softwarová Záchrana 3 / Softwarova-zachrana-3.bin / TextHarvest / TextHarvest-Install.exe / {app} / Help-FlowControl.txt < prev    next >
Text File  |  2005-02-19  |  16KB  |  311 lines

  1. <h1>Parse-O-Matic: Flow Control</h1>
  2.  
  3. <hl>Note: This is an appendix to the "Parse-O-Matic Scripts" user manual.</hl>
  4.  
  5. <h2>Table of Contents</h2>
  6.  
  7. You can click on any section title below to jump directly to that section.
  8.  
  9.    <a href="#BASICFLC"><fs x="1.25"><b>Basic Flow Control</b></fs></a>
  10.       <a href="#AGAINCOM">Again</a>
  11.       <a href="#BEGINCOM">Begin</a>
  12.       <a href="#BREAKCOM">Break</a>
  13.       <a href="#CALLCOMM">Call</a> *
  14.       <a href="#CONTINUE">Continue</a>
  15.       <a href="#DONECOMM">Done</a>
  16.       <a href="#ELSECOMM">Else</a>
  17.       <a href="#ENDCOMMA">End</a>
  18.       <a href="#EXITCOMM">Exit</a> *
  19.       <a href="#IFCOMMAN">If</a>
  20.       <a href="#OTHERWIS">Otherwise</a>
  21.       <a href="#PROCEDUR">Procedure</a> *
  22.       <a href="#STOPCOMM">Stop</a>
  23.    <a href="#STEPCONT"><fs x="1.25"><b>Step Control</b></fs></a>
  24.       <a href="#FILEINIT">FileInit and FileDone</a>
  25.       <a href="#TASKINIT">TaskInit and TaskDone</a>
  26.       <a href="#NEXTSTEP">NextStep</a>
  27.  
  28.    * This feature requires the Advanced Scripting License
  29.  
  30. <a name="BASICFLC"><h1>Basic Flow Control</h1>
  31.  
  32. The basic flow control commands, (such as If, Begin, End, Again, Stop), let you control the order in which the lines of your script are executed. You can, for example, execute a block of commands only under certain circumstances, or cause a group of commands to be executed repeatedly ("looping").
  33.  
  34. <a name="AGAINCOM"><h2>Again</h2>
  35.  
  36. Format         Again [v1 k2 v3]
  37. Examples       See the <a href="#BEGINCOM">Begin</a> command
  38. Purpose        Causes a <a href="#BEGINCOM">Begin</a> block to repeat if the comparison is true (or if
  39.                no comparison is specified)
  40. Parameters     v1 - Value to be compared
  41.                k2 - <a href="pommel://Help-Comparators.txt">Comparator</a> (click for details)
  42.                v3 - Value to compare to v1
  43. Restrictions   You cannot combine an Again command with an If command.
  44.  
  45. <a name="BEGINCOM"><h2>Begin</h2>
  46.  
  47. Format         Begin [v1 k2 v3]
  48. Example        Begin MyVar = 'XYZ'  ; Execute block if MyVar equals 'XYZ'
  49. Purpose        Marks the start of a conditional block of script code
  50. Parameters     v1 - Value to be compared
  51.                k2 - <a href="pommel://Help-Comparators.txt">Comparator</a> (click for details)
  52.                v3 - Value to compare to v1
  53. Defaults       If no comparison is specified, the block always begins. In such
  54.                case, it makes no sense to have an <a href="#ELSECOMM">Else</a> command, and it almost
  55.                invariably means that the block will end with an <a href="#AGAINCOM">Again</a> command.
  56. Restrictions   You cannot combine a Begin command with an If command.
  57. Similar Cmds   If
  58. Notes          Comparisons are not case-sensitive, so 'CAT' = 'Cat' (unless
  59.                you have altered the CompareCtrl setting).
  60.                The Begin command does <b>not</b> set the $Success variable!
  61.                Begin blocks can be nested up to 25 levels deep.
  62.  
  63. Here is an example of the Begin command, used with Else and End:
  64. <hl>
  65.   Begin MyVar = 'Cat'
  66.     OutEnd 'The animal is feline'      ; Executed if MyVar = 'Cat'
  67.     OutEnd 'In fact, it is a cat'      ; Executed if MyVar = 'Cat'
  68.   Else
  69.     OutEnd 'The animal is not feline'  ; Executed if MyVar is <b>not</b> 'Cat'
  70.   End
  71. </hl>
  72. Note the use of indentation. Indentation of the conditional code blocks is not mandatory, but it does make a complicated script much easier to understand. This is particularly important if a Begin block contains other Begin blocks:
  73. <hl>
  74.   Begin CustCode[1 3] = 'USA'
  75.     OutEnd 'The customer is in the USA'
  76.     Begin CustCode[4 5] = 'NY'
  77.       OutEnd 'The customer is in New York'
  78.     End
  79.     Begin CustCode[4 5] = 'TX'
  80.       OutEnd 'The customer is in Texas'
  81.     End
  82.   End
  83. </hl>
  84. Without the indentation, the logic of the code above would be hard to follow.
  85.  
  86. Here is an example of the Begin command used in a loop:
  87. <hl>
  88.   Counter = 0
  89.   Begin
  90.     Counter = Counter+
  91.     OutEnd 'The counter equals ' Counter
  92.   Again Counter #< 10
  93. </hl>
  94. This would output the numbers from 1 to 10. You could also do it this way:
  95. <hl>
  96.   Counter = 0
  97.   Begin Counter #< 10
  98.     Counter = Counter+
  99.     OutEnd 'The counter equals ' Counter
  100.   Again
  101. </hl>
  102. This would output the numbers from 1 to 10.
  103.  
  104. If you wish, you can put comparisons on both the Begin and Again. Both tests are repeated on every iteration of the loop.
  105.  
  106. <a name="BREAKCOM"><h2>Break</h2>
  107.  
  108. Format         Break
  109. Example        If CustNum = MaxCustNum Break
  110. Purpose        Breaks out of the current Begin/Again block, carrying on
  111.                execution at the line following the next Again command
  112. Similar Cmds   Continue
  113.  
  114. <a name="CALLCOMM"><h2>Call</h2>
  115.  
  116. Format         Call v1 [v2 v3 v4...]
  117. Example        Call MyProcedure 'Hello!'  ; Pass 'Hello!' to MyProcedure
  118. Purpose        Invoke a generalized section of script code
  119. Parameters     v1 - The name of the <a href="#PROCEDUR">Procedure</a>; doubles as a variable for
  120.                     passing information to and receiving results back from
  121.                     the Procedure
  122.                v2 - Value (any number of values can be appended)
  123. Defaults       If v2 is not specified, the procedure variable v1 is assigned
  124.                a null value.
  125. Restrictions   Calls from procedures into other procedures, which in turn call
  126.                other procedures (and so on), can nest up to 50 levels deep.
  127.  
  128. When you Call a procedure, execution of the script jumps to the first line of the procedure and continues until the corresponding End statement. The name of the procedure is also the variable name containing any parameters passed in v2, v3 and so on (the values are concatenated). Here is a sample script:
  129. <hl>
  130.   Call OutWithExclaim 'Hello, ' ' world'    ; Call the procedure
  131.   OutEnd 'Glad you could join us!'          ; This line is run after the Call
  132.   Stop                                      ; Stop running script lines
  133.  
  134.   Procedure OutWithExclaim                  ; Start of the procedure
  135.     OutWithExclaim = OutWithExclaim '!'     ; Add an exclamation point
  136.     OutEnd OutWithExclaim                   ; Output
  137.   End                                       ; Return to the line after the Call
  138. </hl>
  139. This would output the string 'Hello, world!' then return to the line following the Call command.
  140.  
  141. <a name="CONTINUE"><h2>Continue</h2>
  142.  
  143. Format         Continue
  144. Example        If Status = 'Ignore' Continue
  145. Purpose        Jumps ahead to the Again of the current Begin/Again block
  146. Similar Cmds   Break
  147.  
  148. <a name="DONECOMM"><h2>Done</h2>
  149.  
  150. Format         Done
  151. Purpose        Skips the rest of the script (for the current record)
  152. Similar Cmds   Stop, NextStep
  153. Notes          The Done command is usually used with the <b><a href="#IFCOMMAN">If</a></b> command,
  154.                or at the end of a Begin/End block.
  155.  
  156. <a name="ELSECOMM"><h2>Else</h2>
  157.  
  158. Format         Else
  159. Example        See the <a href="#BEGINCOM">Begin</a> command
  160. Purpose        Defines the start of the conditional code block that is
  161.                executed if the <a href="#BEGINCOM">Begin</a> comparison is false.
  162. Restrictions   You cannot combine an Else command with an If command.
  163.  
  164. <a name="ENDCOMMA"><h2>End</h2>
  165.  
  166. Format         End
  167. Examples       See the <a href="#BEGINCOM">Begin</a> command
  168. Purpose        Marks the end of a <a href="#BEGINCOM">Begin</a> block
  169. Restrictions   You cannot combine an End command with an If command.
  170.  
  171. <a name="EXITCOMM"><h2>Exit</h2>
  172.  
  173. Format         Exit
  174. Purpose        Immediately returns from a Procedure
  175. Restrictions   The Exit command can only be used inside a <a href="#PROCEDUR">Procedure</a>.
  176. Notes          The Exit command is typically used in conjunction with a
  177.                comparison. You do <b>not</b> need to include an Exit command
  178.                in every Procedure.
  179.  
  180. <a name="IFCOMMAN"><h2>If</h2>
  181.  
  182. Format         If v1 k2 v3 c4
  183. Examples       If CustCode = 'AB12' OutEnd 'Mary Smith'
  184.                If CustCode = 'CD34' CustAddr = '1234 Happy Lane'
  185. Purpose        Conditionally performs a command
  186. Parameters     v1 - Value to be compared
  187.                k2 - <a href="pommel://Help-Comparators.txt">Comparator</a> (click for details)
  188.                v3 - Value to compare to v1
  189.                c4 - Command
  190. Restrictions   The If command may not be combined with a command that defines
  191.                the start of a code block, such as Begin or FileInit.
  192. Similar Cmds   Begin, End, Again
  193. Notes          The comparison is case-insensitive, so 'CAT' = 'cat' unless
  194.                you have altered the CompareCtrl setting.
  195.                The If command does <b>not</b> set the $Success variable!
  196.  
  197. In deference to the ingrained training of seasoned programmers, you may use the word "then" after the comparison. Thus, the following command will be accepted:
  198. <hl>
  199.   If x > y then z = 'Hello'
  200. </hl>
  201. This usage is non-standard, however, and is not recommended. The scripting engine treats the "then" as a variable, but ignores it in this context. Thus, you should never use a variable named "Then".
  202.  
  203. The If command does not have an "Else" option as in most programming languages. To execute a command when the If condition is false, use the <a href="#OTHERWIS">Otherwise</a> command. Alternatively, you can use the Begin command with an Else section.
  204.  
  205. <a name="OTHERWIS"><h2>Otherwise</h2>
  206.  
  207. Format         Otherwise c1
  208. Example        If Animal = 'Cat' Type = 'Feline'  ; The initial If command
  209.                Otherwise Type = 'Non-feline'      ; Action taken if false
  210. Purpose        Executes an alternative command when the If comparison is false
  211. Parameters     c1 - Command
  212. Restrictions   The Otherwise command must follow immediately after an If.
  213.                The Otherwise command may not be combined with a command that
  214.                defines the start of a code block, such as Begin or FileInit.
  215. Similar Cmds   Else
  216.  
  217. <a name="PROCEDUR"><h2>Procedure</h2>
  218.  
  219. Format         Procedure v1
  220. Example        Procedure MyCode
  221. Purpose        Defines the start of a generalized section of script code, which
  222.                is terminated with the End command
  223. Parameters     v1 - The name of the Procedure (must be a simple variable)
  224. Restrictions   Recursive procedures (i.e. procedures that call themselves) are
  225.                not formally supported and their use is not recommended.
  226. Notes          See the <a href="#CALLCOMM">Call</a> command for a full discussion of procedures.
  227.  
  228. As the script is being run, any Procedure sections are ignored when encountered; they are only executed when explicitly invoked by <a href="#CALLCOMM">Call</a>. Procedures can go anywhere except within conditional blocks such as Begin/End, FileInit/End and so on. Procedures are usually placed together at the end of the script.
  229.  
  230. <a name="STOPCOMM"><h2>Stop</h2>
  231.  
  232. Format         Stop [v1]
  233. Example        If CustNum[1] = 'X' Stop 'Invalid customer number'
  234. Purpose        Terminates further processing
  235. Parameters     v1 - Optional pop-up message
  236. Similar Cmds   Done, NextStep
  237. Notes          If v1 is included, a pop-up message is displayed. In such case,
  238.                the Stop is considered an "abnormal" end of processing and the
  239.                script-enabled application should proceed accordingly.
  240.  
  241. <a name="STEPCONT"><h1>Step Control</h1>
  242.  
  243. A simple script runs from top to bottom each time a record is sent to it. But how can you initialize variables before processing starts? How can you output a grand total after all the records have been processed?
  244.  
  245. These issues and others are addressed by the step control commands.
  246.  
  247. When processing files, Parse-O-Matic performs a series of steps:
  248. <hl>
  249.   TaskInit   Executes before data is read from the  <b>first</b>  input file
  250.   FileInit   Executes before data is read from the <b>current</b> input file
  251.   Main       Executes once for each record sent to the script
  252.   FileDone   Executes after the last data is read from the <b>current</b> input file
  253.   TaskDone   Executes after the last data is read from the  <b>last</b>   input file
  254. </hl>
  255. If you are only processing a single file (i.e. you are not using wildcards to process multiple input files), there is little to distinguish TaskInit and TaskDone from FileInit and FileDone.
  256.  
  257. Except for the Main step, each step appears inside a conditional block, as in this example:
  258. <hl>
  259.   TaskInit                                        ; Start of the TaskInit step
  260.     OutEnd 'Customer Count Report'                ; Report header
  261.     OutEnd '---------------------'                ; Report header
  262.   End                                             ; End of the TaskInit step
  263.  
  264.   FileInit                                        ; Start of the FileInit step
  265.     OutEnd 'Input file: ' $ActualIFN              ; Output the file name
  266.     NumInpFiles = NumInpFiles+                    ; Count this input file
  267.   End                                             ; End of the FileInit step
  268.  
  269.   CustCount = CustCount+                          ; Main step: count record
  270.  
  271.   TaskDone                                        ; Start of the TaskDone step
  272.     OutNull                                       ; Output a blank line
  273.     OutEnd 'Number of input files: ' NumInpFiles  ; Output statistics
  274.     OutEnd 'Number of customers:   ' CustCount    ; Output statistics
  275.   End                                             ; End of the TaskDone step
  276. </hl>
  277. In the example given above, the conditional code for the report header was placed in TaskInit so that the script will output it only once, even if you are processing multiple input files.
  278.  
  279. The conditional steps are optional. For example, you do not have to include FileInit in your script.
  280.  
  281. The conditional steps can appear almost anywhere in your script (though not within another conditional block).
  282.  
  283. <a name="FILEINIT"><h2>FileInit and FileDone</h2>
  284.  
  285. The FileInit section is executed before each input file is processed. The FileDone section is executed after each input file is processed. For details, click <a href="#STEPCONT">here</a>.
  286.  
  287. You cannot combine the FileInit or FileDone commands with the If command.
  288.  
  289. <a name="TASKINIT"><h2>TaskInit and TaskDone</h2>
  290.  
  291. The TaskInit section is executed before data is read from the first input file. The TaskDone section is executed after the last record is read from the last input file. For additional details, click <a href="#STEPCONT">here</a>.
  292.  
  293. You cannot combine the TaskInit or TaskDone commands with the If command.
  294.  
  295. <a name="NEXTSTEP"><h2>NextStep</h2>
  296.  
  297. The NextStep command can be used to jump out of a <a href="#STEPCONT">step</a> (such as FileInit or Main) and proceed to the next step.
  298.  
  299. For example, if your Main step has already located the information you are seeking, there is no reason to continue reading the input file. In such case, you can execute a NextStep command to ignore the rest of the input file and proceed immediately to FileDone, as in the following example.
  300. <hl>
  301.   CustNum  = $OutData[1 6]              ; Main step: Get customer number
  302.   PhoneNum = $OutData[60 70]            ; Main step: Get the phone number
  303.   If CustNum = '314159' NextStep        ; Main step: Found the customer?
  304.  
  305.   FileDone                              ; Start of the FileDone step
  306.     OutEnd 'Phone Number = ' PhoneNum   ; Output the information we sought
  307.   End                                   ; End of the FileDone step
  308. </hl>
  309. NextStep should not be confused with the <a href="#STOPCOMM">Stop</a> command, which causes processing to cease entirely.
  310.  
  311. NextStep is also different from <a href="#DONECOMM">Done</a>, which skips the rest of the script and then (if used in the Main step) proceeds to process the next record from the input file. The Done command can, however, be used within a conditional step block (such as FileInit) to skip the rest of that step; in such case it will behave the same way as NextStep.